<%--
  Created by IntelliJ IDEA.
  User: 123
  Date: 2020/3/31
  Time: 11:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-1.11.3.min.js"></script>
</head>
<script>
    //绑定方法
    function binder(){
        //获取用户名
        var username =  $("#username").val();
        //获取openid   /bind.jsp?openid=1231231231  --['/bind.jsp?openid',1231231231]
        var openid = location.href.split("=")[1];
        //发送ajax进行绑定账号 jquery
        var params={
            username:username,
            openid:openid
        }
        //$.get $.post $.ajax
        $.ajax({
            type: "post",
            dataType: "json",
            url: "/binder",
            contentType: "application/json;charset=UTF-8",//指定消息请求类型
            data: JSON.stringify(params),//将js对象转成json字符串
            success: function (data) {
                //data =  $.parseJSON(data);
                console.log(data);
                if (data.success) {
                    location.href = "/index.jsp"
                }else{
                    location.href = "/login"
                }
            }
        })

    }
</script>
<body>
    <form>
        用户名<input type="text" id="username" name="username"/>
            <input type="button" value="绑定" onclick="binder()"/>
    </form>
</body>
</html>
